// stores/login-user.js
import {
	defineStore
} from 'pinia';

export const useCounterStore = defineStore('login-user', {
	state: () => ({
		token: "",
		/**
		 * 是否需要强制登录
		 */
		// #ifdef MP-WEIXIN
		db: null,
		orgCode: '',
		orgList: [],
		openid: '',
		// #endif
		isadmin: false,
		subUrl: '', //子路径
		forcedLogin: true,
		hasLogin: false,
		orgName: 'O&M', //组织全称
		orgShortName: 'OM', //组织简称
		userId: null,
		userName: '',
		mobile: '',
		salaryPosId: null,
		salaryPosName: "",
		salaryInstId: null,
		salaryInstName: "",
		salaryOfficeId: null,
		orgId: null,
		areaId: "",
		areaCode: "",
		areaName: "",
		avatar: "",
		sexCode: "",
		pendingReload: false, //待处理更新
		unreadReload: false, //未阅读更新
		recentWorkReload: false, //近期工作更新
		subTableShowType: 0, //)约束移动端表格列表或明细显示方式约束；)默认值为0，取值范围为0-1；)设置的值为0时，按表格显示，设置的值为1时，分条用明细展开显示。
	}),
	actions:{
		// #ifdef MP-WEIXIN
		setDb(db) {
			this.db = db;
		},
		setOpenid(openid) {
			this.openid = openid;
		},
		setOrgList(orgList) {
			this.orgList = orgList;
		},
		setOrgCode(orgCode) {
			this.orgCode = orgCode;
		},
		// #endif
		setUserId(userId) {
			this.userId = userId;
		},
		setOrgName(orgName) {
			this.orgName = orgName;
		},
		setSubUrl(subUrl) {
			this.subUrl = subUrl;
		},
		setHasLogin(hasLogin) {
			this.hasLogin = hasLogin;
		},
		setAvatar(avatar) {
			this.avatar = avatar;
		},
		setPending(pendingReload) {
			this.pendingReload = pendingReload;
		},
		setUnread(unreadReload) {
			this.unreadReload = unreadReload;
		},
		setRecentWork(recentWorkReload) {
			this.recentWorkReload = recentWorkReload;
		},
		setToken(token){
			this.token = "Bearer " + token;
		},
		clearToken(state,token){
			this.token = "";
		},
		login(sessionInfo) {
			this.hasLogin = true;
			this.userName = sessionInfo.username || '';
			this.mobile = sessionInfo.mobile || '';
			this.orgName = sessionInfo.orgname || '';
			this.salaryPosId = sessionInfo.salaryPosId || '';
			this.salaryPosName = sessionInfo.salaryPosName || '';
			this.salaryInstId = sessionInfo.salaryInstId || '';
			this.salaryInstName = sessionInfo.salaryInstName || '';
			this.salaryOfficeId = sessionInfo.salaryOfficeId || '';
			this.orgShortName = sessionInfo.shortOrgname || '';
			this.userId = sessionInfo.userid;
			this.orgId = sessionInfo.orgid;
			this.areaId = sessionInfo.areaId
			this.areaCode = sessionInfo.areaCode
			this.areaName = sessionInfo.areaName
			this.avatar = this._vm.om.getUrl(sessionInfo.avatar);
			this.sexCode = sessionInfo.sexCode;
			this.subTableShowType = sessionInfo.subTableShowType;
			if (sessionInfo.isSysAdmin != undefined && sessionInfo.isSysAdmin != null) {
				this.isadmin = sessionInfo.isSysAdmin
			}
			// #ifdef MP-WEIXIN
			this.orgCode = sessionInfo.orgCode;
			// #endif
		},
		logout(state) {
			this.token = "";
			this.userName = "";
			this.mobile = '';
			this.hasLogin = false;
			this.orgName = "";
			this.orgShortName = "";
			this.userId = null;
			this.orgId = null;
			this.areaId = null;
			this.areaCode = "";
			this.areaName = "";
			this.subUrl = "";
			this.salaryPosId = null;
			this.salaryPosName = "";
			this.salaryInstId = null;
			this.salaryInstName = "";
			this.salaryOfficeId = "";
			this.isadmin = false;
			// #ifdef MP-WEIXIN
			this.orgCode = "";
			this.orgList = [];
			this.openid = "";
			// #endif
		}
	}
});